package leetcode;

public class ImplementQueueUsingStacks232 {
    class ArrayQueue {
        Object[] array;
        int top = 0;

        public ArrayQueue(int capacity) {
            array = new Object[capacity];
        }

        public boolean isFull() {
            return top == array.length;
        }

        public boolean isEmpty() {
            return top == 0;
        }

        public boolean push(Object val) {
            if (isFull()) {
                return false;
            }
            array[top++] = val;
            return true;
        }

        public Object pop() {
            if (isEmpty()) {
                return null;
            }
            return array[--top];
        }

        public Object peek() {
            if (isEmpty()) {
                return null;
            }
            return array[top - 1];
        }
    }

    ArrayQueue q1 = new ArrayQueue(100);
    ArrayQueue q2 = new ArrayQueue(100);
    public void push(int x) {
        q2.push(x);
    }

    public int pop() {
        if(q1.isEmpty()){
            while(!q2.isEmpty()){
                q1.push(q2.pop());
            }
        }
        return (int) q1.pop();
    }

    public int peek() {
        if(q1.isEmpty()){
            while(!q2.isEmpty()){
                q1.push(q2.pop());
            }
        }
        return (int) q1.peek();
    }

    public boolean empty() {
        return q1.isEmpty() && q2.isEmpty();
    }

    public static void main(String[] args) {
        ImplementQueueUsingStacks232 i = new ImplementQueueUsingStacks232();
        System.out.println(i.empty());
    }
}
